import tkinter as tk
from tkinter import messagebox

# 玩家手牌数据
player_hands = [
    ["A♥", "2♥", "3♥", "4♥"],  # 下方玩家
    ["A♠", "2♠", "3♠", "4♠"],  # 右侧玩家
    ["A♣", "2♣", "3♣", "4♣"],  # 上方玩家
    ["A♦", "2♦", "3♦", "4♦"]   # 左侧玩家
]

current_turn = 0
played_cards = [None, None, None, None]  # 分别对应下、右、上、左四个位置的出牌

def play_card(card_index):
    global current_turn
    card = player_hands[current_turn].pop(card_index)
    played_cards[current_turn] = card  # 记录当前玩家的出牌
    update_display()
    current_turn = (current_turn + 1) % 4
    if current_turn == 0:
        # 一轮结束，清空出牌记录
        played_cards[:] = [None, None, None, None]

def update_display():
    # 清空所有显示区域
    for frame in [central_frame, bottom_frame, right_frame, top_frame, left_frame]:
        for widget in frame.winfo_children():
            widget.destroy()

    # 显示中央出牌区域（四个方向的牌）
    positions = ["bottom", "right", "top", "left"]
    for i, card in enumerate(played_cards):
        if card:
            label = tk.Label(central_frame, text=card, font=("Arial", 20))
            if positions[i] == "bottom":
                label.grid(row=2, column=1, pady=(5, 0))
            elif positions[i] == "right":
                label.grid(row=1, column=2, padx=(5, 0))
            elif positions[i] == "top":
                label.grid(row=0, column=1, pady=(0, 5))
            elif positions[i] == "left":
                label.grid(row=1, column=0, padx=(0, 5))

    # 添加中央网格布局配置
    central_frame.grid_rowconfigure(0, weight=1)
    central_frame.grid_rowconfigure(1, weight=1)
    central_frame.grid_rowconfigure(2, weight=1)
    central_frame.grid_columnconfigure(0, weight=1)
    central_frame.grid_columnconfigure(1, weight=1)
    central_frame.grid_columnconfigure(2, weight=1)
    current_hand = player_hands[current_turn]
    for i, card in enumerate(current_hand):
        button = tk.Button(bottom_frame, text=card, font=("Arial", 16),
                         command=lambda index=i: play_card(index))
        button.pack(side=tk.LEFT, padx=5)
# ... 前面的代码保持不变 ...

# 创建主窗口
root = tk.Tk()
root.title("红心大战")
root.geometry("800x600")  # 设置固定窗口大小
root.resizable(False, False)  # 禁止调整窗口大小

# 中央出牌区域
central_frame = tk.Frame(root)
central_frame.pack(expand=True, fill=tk.BOTH)
central_frame.grid_propagate(False)  # 禁止自动调整大小

# 四个方向的手牌区域
top_frame = tk.Frame(root, height=100)
top_frame.pack(side=tk.TOP, fill=tk.X)
left_frame = tk.Frame(root, width=100)
left_frame.pack(side=tk.LEFT, fill=tk.Y)
right_frame = tk.Frame(root, width=100)
right_frame.pack(side=tk.RIGHT, fill=tk.Y)
bottom_frame = tk.Frame(root, height=100)
bottom_frame.pack(side=tk.BOTTOM, fill=tk.X)

# ... 后面的代码保持不变 ...

# 初始化显示
update_display()

# 运行主循环
root.mainloop()